<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__CSS__/layui.css">
    <link rel="stylesheet" href="__CSS__/view.css"/>
    <link rel="icon" href="/favicon.ico">
    <title>代理商管理</title>
</head>
<style>
    .pagination { display: inline-block; padding-left: 0; margin: 20px 0; border-radius: 4px; }
    .pagination li { display: inline; }
    .pagination li a { position: relative;background-color: #fff; border: 1px solid #ddd; }
    .layui-btn+.layui-btn {margin-left: 1px;}
</style>
<body class="layui-view-body">
    <div class="layui-content">
        <div class="layui-page-header">
            <div class="pagewrap">
                <span class="layui-breadcrumb">
                  <a href="">首页</a>
                  <a href="">代理商管理</a>
                </span>
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="form-box">
                    <form action="{:Url('agent/user/agentlist')}" id="form">
                        <div class="layui-form layui-form-item">
                            <div class="layui-inline">
                                <div class="layui-form-mid">用户名:</div>
                                <div class="layui-input-inline" style="width: 100px;">
                                  <input type="text" autocomplete="off" value="{$account}" name="account" class="layui-input">
                                </div>
                                <div class="layui-form-mid">姓名:</div>
                                <div class="layui-input-inline" style="width: 100px;">
                                  <input type="text" autocomplete="off" value="{$name}" name="name" class="layui-input">
                                </div>
                                <button class="layui-btn layui-btn-blue" id="sub">查询</button>
                                <button class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </form>
                        <button class="layui-btn layui-btn-blue" id="addagent"><i class="layui-icon" >&#xe654;</i>新增代理</button>
                        <table class="layui-table">
                          <thead>
                            <tr>
                              <th>ID</th>
                              <th>用户名</th>
                              <th>推广码</th>
                              <th>姓名</th>
                              <th>电话</th>
                              <th>注册时间</th>
                              <th>状态</th>
                              <th >操作</th>
                              </tr>
                          </thead>
                          {volist name="list" id="vo"}
                          <tbody>
                            <tr>
                              <td>{$vo.user_id}</td>
                              <td>{$vo.user_account}</td>
                              <td>{$vo.user_code}</td>
                              <td>{$vo.user_name}</td>
                              <td>{$vo.user_phone}</td>
                              <td>{$vo.user_time|date="Y-m-d H:i:s"}</td>
                              {if $vo.user_state==1}
                              <td>冻结</td>
                              {else}
                              <td>正常</td>
                              {/if}
                              <td class="td-manage">
                                <a title="" class="layui-btn layui-btn-xs" onclick="next_agent_show({$vo.user_id})" href="javascript:;">
                                  下级代理
                                </a>
                                <a title="" class="layui-btn layui-btn-normal layui-btn-xs" onclick="next_user_show({$vo.user_id})" href="javascript:;">
                                  下级用户
                                </a>
                                <a title="" class="layui-btn layui-btn-warm layui-btn-xs" onclick="agent_edit({$vo.user_id})" href="javascript:;">
                                  编辑
                                </a>
                                <a title="" class="layui-btn layui-btn-danger layui-btn-xs" onclick="agent_dels({$vo.user_id})" href="javascript:;">
                                  删除
                                </a>
                              </td>
                            </tr>
                          </tbody>
                          {/volist}
                        </table>
                    </div>
                </div>
            </div>
        </div>
    <div id="page" style="float: right;">
      <div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-1">
        {$list|raw}
      </div>
    </div>
    </div>
    <script src="__JS__/layui.all.js"></script>
    <script src="__JS__/layer/layer.js"></script>
    <script src="__JS__/jquery.min.js"></script>
    <script>
    //查看下级代理
      function next_agent_show(user_id){
        window.location.href = "{:Url('member/user/index')}?pid="+user_id;
      }
    //查看下级客户
      function next_user_show(user_id){
        window.location.href = "{:Url('member/user/user')}?pid="+user_id+'&type=2';
      }
    //新增代理
      $("#addagent").click(function(){
        var url = "{:Url('member/user/Addagent')}"
        layer.open({
          type: 2,
          skin: 'layui-layer-rim', //加上边框
          area: ['60%', '90%'], //宽高
          content: url
        });
      })
      $("#sub").click(function(){
        $("#form").submit();
      })
    //编辑代理信息
      function agent_edit(user_id){
        var url = "{:Url('member/user/Upagent')}?id="+user_id;
        layer.open({
          type: 2,
          skin: 'layui-layer-rim', //加上边框
          area: ['60%', '90%'], //宽高
          content: url
        });
      }

      // 删除代理
      function agent_dels(user_id){
          layer.confirm('是否确定删除该代理商', {
            btn: ['确认','取消'] //按钮
          }, function(){
              var urls = "{:Url('member/user/agent_del')}";
              $.get(urls, {aid:user_id}, function(e){
                  if(e.error == '1'){
                      layer.msg(e.msg);
                      return false;
                  }else if(e.error == '0'){
                      layer.msg(e.msg);
                      setTimeout(function(){
                          location.reload();
                      },1500) 
                  }
              });
          }, function(){});
      }
    </script>
</body>
</html>